<template>
	<div class="orderDetails">
    <!-- 销售单明细 -->
		<FormPanel
		  :list="formList"
		  :cols="3"
		  labelWidth='90'
		  :isSubmitBtn="false"
		  :formType="type"
		  @formChange="changeHandle"
		/>

		<div class="upWard">
			<el-button size="small" type="primary" @click="closeDialog">返回</el-button>
		</div>
	</div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { salesOrders } from '@/api/retail/salesmanage/salesordermanage';

export default {
  name: 'orderDetails',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'show'
    },
    rowData : {
      type: Object,
      default: () => ({})
    }
  },
	data (){
		return {
		  	formList: this.createFormList()



		}
  },
  mounted (){
    this.init();
  },
	methods: {
    init (){
      // console.log(this.type)
      // console.log(this.rowData)
      this.ordeDetails(this.rowData);
    },
    async ordeDetails (row){  //根据父组件传递的ID获取详细数据并赋值
      let res = await salesOrders(row.soVinId)
      console.log(res)
  		if(res.resultCode == 200){
        res.data.deliveringDate = this.formatDates(res.data.deliveringDate);
        this.formList.forEach(x => x.initialValue = res.data[x.fieldName]);
  		}
    },
		createFormList (){
			return [
				{
          type: 'INPUT',
          label: '客户订单号',
          fieldName: 'soNo',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '销售订单号',
          fieldName: 'viNo',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'customerNo',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'SELECT',
          label: '订单状态',
          fieldName: 'soStatus',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1404')
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '手机号码',
          fieldName: 'mobilePhone',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: 'VIN号',
          fieldName: 'salesVin',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'DATE',
          label: '预交车日期',
          fieldName: 'deliveringDate',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '品牌',
          fieldName: 'brandName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'seriesName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '配置',
          fieldName: 'packageName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '颜色',
          fieldName: 'colorName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '销售指导价',
          fieldName: 'directivePrice',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '销售单价',
          fieldName: 'vehiclePrice',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '开票名称',
          fieldName: 'invoiceName',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '开票联系人',
          fieldName: 'invoiceLinkMan',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '开票电话',
          fieldName: 'invoiceMobile',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '开票地址',
          fieldName: 'invoiceAddress',
          placeholder: '',
          initialValue: '',
        }



			]
		},
		changeHandle(val){ //点击保存按钮出发的事件
      console.log('表单面板的数据：', val);
    },
    closeDialog (){ //返回上层
      this.$emit('close', false);
    },

    formatDates: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == "") {
        return "";
      }
      var date = new Date(Number(value));
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + "-" + month + "-" + day;
    },

	}

}
</script>

<style scoped="scoped" lang="less">
.upWard{
	margin-top: 15px;
	text-align: center;
}
</style>
